package com.kinglone.servlet;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = "/ydjcbusiness/eqpMgr")
public class EqpMgrController {

	private static final Logger logger = Logger.getLogger(EqpMgrController.class);
	

//	private EqpMgrService eqpMgrService;
	

      
    /*@SuppressWarnings("unused")
	@RequestMapping(value="/submitDataapp.html")
    @ResponseBody
    public ResultMsg submitDataapp(HttpServletRequest request,@RequestParam("IMGFILE") MultipartFile IMGFILE, @RequestParam("APL_USER_NAME") String APL_USER_NAME,
    		@RequestParam("USE_UNT_ID") String USE_UNT_ID,@RequestParam("EQP_STATUS") String EQP_STATUS,@RequestParam("EQP_ID") String EQP_ID,
    		@RequestParam("TOKEN") String TOKEN) throws Exception {
    	
			ResultMsg msg = new ResultMsg(false, null, "文件上传失败!");
		    	
			System.out.println("APL_USER_NAME:"+APL_USER_NAME+"---USE_UNT_ID:"+USE_UNT_ID+"---EQP_STATUS:"+EQP_STATUS+"---EQP_ID:"+EQP_ID);
			
			if(!IMGFILE.isEmpty()) {
				
			   String filename = IMGFILE.getOriginalFilename();
			   String fileType = filename.substring(filename.lastIndexOf(".")+1);   //文件格式 	                 		
			   long length = IMGFILE.getSize(); 
			   
			   String basepath=PropertieUtil.getValue("config.properties", "upload_url");								
			   String relativePath="/upload/"+DateUtils.format(new Date(), "yyyyMMdd")+"/";
			   String holePath=basepath.trim()+relativePath;//文件路径,不包含文件
			   
			   File f=new File(holePath);
			   if(!f.exists()){
				  f.mkdirs();			  
			 }
		   
			   //组成文件实际路径 
			   String truePath=holePath+filename;
			   System.out.println("实际路径为："+truePath);       	
			   IMGFILE.transferTo(new File(truePath));
			   String imgUrl = relativePath+filename;//文件保存相对路径

			
			   String url = "http://192.168.1.155:7001/FJJC/servlet";   	   		  
			   String result = null ;
		    
			   OkHttpClient client = new OkHttpClient();
			   client.setConnectTimeout(60,TimeUnit.SECONDS);
			   client.setReadTimeout(100, TimeUnit.SECONDS);
			   client.setWriteTimeout(60, TimeUnit.SECONDS);
		
			MediaType mediaType = MediaType.parse("image/png");
			RequestBody requestBody = new MultipartBuilder()
				.type(MultipartBuilder.FORM)
				.addPart(Headers.of("Content-Disposition", "form-data; name=\"USE_UNT_ID\""),
						RequestBody.create(null, USE_UNT_ID))
				.addPart(Headers.of("Content-Disposition", "form-data; name=\"EQP_STATUS\""),
						RequestBody.create(null, EQP_STATUS))
				.addPart(Headers.of("Content-Disposition", "form-data; name=\"APL_USER_NAME\""),
						RequestBody.create(null, APL_USER_NAME))
				.addPart(Headers.of("Content-Disposition", "form-data; name=\"EQP_ID\""),
						RequestBody.create(null, EQP_ID))
				.addPart(Headers.of("Content-Disposition", "form-data; name=\"TOKEN\""),
						RequestBody.create(null, TOKEN))
				.addFormDataPart("multipart/form-data", filename, RequestBody.create(mediaType, new File(truePath)))
				.build();
			
			Request re = new Request.Builder()
				.url(url)
				.post(requestBody)
				.addHeader("cache-control", "no-cache")
				.build();
			try {
				Response response = client.newCall(re).execute();
			    result = response.body().string() ;
			    System.out.println("---:"+result);
			} catch (IOException e) {
				e.printStackTrace();
			}			 
				 msg.setSuccess(true);
				 msg.setMessage("ok");
				 msg.setData(result);		
		  	   	 System.out.println(msg);
				
			}else{
				 System.out.println("文件不存在");
			}
			     return msg;  
    	}*/
}
